Skip to content

Development#21

Open
mtsthibau wants to merge 11 commits into
mainfrom
development
Open

Development#21
mtsthibau wants to merge 11 commits into
mainfrom
development

Conversation

@mtsthibau
Copy link
Copy Markdown
Contributor

@mtsthibau mtsthibau commented Apr 28, 2026

This pull request introduces new API endpoints for managing the digital voice mode of the radio, improves error handling and validation in user and radio controller methods, and makes minor code cleanups. The most important changes are summarized below:

Digital Voice Mode API Enhancements:

  • Added two new methods, getDigitalVoice and setDigitalVoice, to RadioController for retrieving and updating the digital voice mode. These methods include input validation, command execution, and error logging.
  • Registered corresponding routes in routes/web.php for the new digital voice endpoints: GET radio/voice/digital and POST radio/voice/digital/{value}.

User Controller Improvements:

  • Updated UserController@showOneUser to use User::find($id) instead of searching by email, ensuring the lookup is by user ID and improving reliability.

Radio Controller Validation and Cleanup:

  • Improved input validation in RadioController@setPowerLevel by ensuring the powerLevel is within the valid range before executing the command.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the Lumen /radio API to support getting/setting the radio’s digital voice mode, and updates user lookup to use primary-key ID rather than email.

Changes:

  • Added GET /radio/voice/digital and POST /radio/voice/digital/{value} routes.
  • Implemented RadioController@getDigitalVoice and RadioController@setDigitalVoice.
  • Updated UserController@showOneUser to use User::find($id).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
routes/web.php Registers two new digital voice endpoints under the /radio route group.
app/Http/Controllers/UserController.php Switches single-user lookup to primary-key ID via User::find($id).
app/Http/Controllers/RadioController.php Adds digital voice get/set actions and adjusts power-level validation area.
Comments suppressed due to low confidence (1)

app/Http/Controllers/RadioController.php:988

  • If powerLevel is outside 0..100, the first if block is skipped and $output is never set, but it is still read in if ($output == "OK"), which will raise an undefined variable notice and return a 500. Add an explicit else/early return for invalid powerLevel (and avoid referencing $output when the command was not executed).
		if ($request->powerLevel >= 0 && $request->powerLevel <= 100) {
			$command = "set_power -a " . $request->powerLevel . " -p " .  $request->profile;
			$output = explode("\n", (string) exec_uc($command))[0];
		}

		if ($output == "OK") {
			return response(true, 200);
		}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +927 to +934
public function setDigitalVoice(Request $request)
{
if ($request->value < 0 || $request->value > 1) {
(new ErrorController)->saveError(static::class, 500, 'API Error: digital voice value must be 0 or 1');
return response()->json(['message' => 'Server error'], 500);
}

$command = "set_digital_voice -a " . $request->value. " -p 1";
Comment on lines +928 to +934
{
if ($request->value < 0 || $request->value > 1) {
(new ErrorController)->saveError(static::class, 500, 'API Error: digital voice value must be 0 or 1');
return response()->json(['message' => 'Server error'], 500);
}

$command = "set_digital_voice -a " . $request->value. " -p 1";
$output = explode("\n", (string) exec_uc($command))[0];

if ($output == "OFF" || $output == "ON") {
return response()->json($output, 200);
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

Comments suppressed due to low confidence (1)

app/Http/Controllers/RadioController.php:991

  • If powerLevel is outside the allowed range, $output is never set, but the code still evaluates if ($output == "OK") and logs with ... - $output, which can trigger an undefined variable notice and obscure the real problem. Return a 4xx response (and avoid executing the command) when validation fails, and ensure $output is always defined before it is used.
		if ($request->powerLevel >= 0 && $request->powerLevel <= 100) {
			$command = "set_power -a " . $request->powerLevel . " -p " .  $request->profile;
			$output = explode("\n", (string) exec_uc($command))[0];
		}

		if ($output == "OK") {
			return response(true, 200);
		}

		(new ErrorController)->saveError(static::class, 500, 'API Error: Error during updating the power level - ' . $output);
		return response()->json(['message' => 'Server error'], 500);

Comment thread routes/web.php
Comment thread routes/web.php
Comment thread app/Http/Controllers/RadioController.php Outdated
Comment thread app/Http/Controllers/RadioController.php Outdated
Comment thread app/Http/Controllers/RadioController.php
Comment thread app/Http/Controllers/RadioController.php
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

app/Http/Controllers/RadioController.php:991

  • If powerLevel is outside 0..100, the $output variable is never set, but it is still referenced in the subsequent if ($output == "OK") and error logging. This will trigger an undefined variable notice and can mask the real validation failure. Return a clear validation response when out of range (or set a default/else branch) before using $output.
		if ($request->powerLevel >= 0 && $request->powerLevel <= 100) {
			$command = "set_power -a " . $request->powerLevel . " -p " .  $request->profile;
			$output = explode("\n", (string) exec_uc($command))[0];
		}

		if ($output == "OK") {
			return response(true, 200);
		}

		(new ErrorController)->saveError(static::class, 500, 'API Error: Error during updating the power level - ' . $output);
		return response()->json(['message' => 'Server error'], 500);

Comment thread routes/web.php
Comment thread app/Http/Controllers/RadioController.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FIX | API - Fix stop transmission behavior

5 participants